% fn_freq_location.m
% Function to compute the frequencies of price endings by location.
function bar_data=fn_freq_location(prices);
global fig_no location_categories locations
[rows,cols] = size(prices);
bins = zeros(location_categories,8);
p = [prices zeros(length(prices),1)];
for i = 1:rows
    p(i,6) = fn_multiples(p(i,1));
    if p(i,6) == 20; 
        bins(p(i,3),8) = bins(p(i,3),8) + 1;
    elseif p(i,6) == 10; 
        bins(p(i,3),7) = bins(p(i,3),7) + 1;
    elseif p(i,6) == 5; 
        bins(p(i,3),6) = bins(p(i,3),6) + 1;
    elseif p(i,6) == 1; 
        bins(p(i,3),5) = bins(p(i,3),5) + 1;
    elseif p(i,6) == 0.25; 
        bins(p(i,3),4) = bins(p(i,3),4) + 1;
    elseif p(i,6) == 0.10; 
        bins(p(i,3),3) = bins(p(i,3),3) + 1;
    elseif p(i,6) == 0.05; 
        bins(p(i,3),2) = bins(p(i,3),2) + 1;
    else bins(p(i,3),1) = bins(p(i,3),1) + 1;
    end;
end;
bar_data=bins;
%---------------------------------------------------------------------
% fn_multiples.m
% Determines whether a price is a multiple of a twenty, ten, five or one
% dollar bill, or a quarter, dime or nickel.
function out=fn_multiples(p);
out = 0;
% Multiple of $0.05?
if rem(p,0.05) == 0
    out = 0.05;
end;
% Multiple of $0.10?
if rem(p,0.10) == 0
    out = 0.10;
end;
% Multiple of $0.25?
if rem(p,0.25) == 0
    out = 0.25;
end;
% Multiple of $1?
if rem(p,1) == 0
    out = 1;
end;
% Multiple of $5?
if rem(p,5) == 0
    out = 5;
end;
% Multiple of $10?
if rem(p,10) == 0
    out = 10;
end;
% Multiple of $20?
if rem(p,20) == 0
    out = 20;
end;